package dao.impl;

import dao.ProductInfoDao;
import entity.Product_Info;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import util.C3P0Util;

import java.sql.SQLException;

public class ProductInfoDaoImpl implements ProductInfoDao{
	private QueryRunner getQueryRunner(){
		return new QueryRunner(C3P0Util.getDataSource());
	}
	
	@Override
	public Product_Info queryProduct_InfoById(Integer product_id) {
		String sql = "select * from product_info where product_id = ?";
		QueryRunner qr = this.getQueryRunner();
		Product_Info product_Info=null;
		try {
			product_Info = qr.query(sql, product_id,new BeanHandler<Product_Info>(Product_Info.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return product_Info;
	}

	@Override
	public Product_Info queryProduct_InfoByName(String product_name) {
		Product_Info pi = null;
		QueryRunner qr = this.getQueryRunner();
		String sql = "select * from product_info where product_name=?";
		try {
			pi = qr.query(sql, product_name,new BeanHandler<Product_Info>(Product_Info.class));
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return pi;
	}
	
}
